package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Credit;
import cn.wolfcode.trip.base.domain.Wallet;
import cn.wolfcode.trip.base.mapper.CreditMapper;
import cn.wolfcode.trip.base.mapper.WalletMapper;
import cn.wolfcode.trip.base.service.IWalletService;
import cn.wolfcode.trip.base.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WalletServiceImpl implements IWalletService {
    @Autowired
    private WalletMapper walletMapper;
    @Autowired CreditMapper creditMapper;

    @Override
    public void charge(Wallet wallet) {

        Credit credit = new Credit();
        credit.setUser(UserContext.getCurrentUser());
        credit.setCredits(wallet.getMoney()*10);
        //充值送积分
        creditMapper.updateByPrimaryKey(credit);
        //充值
        walletMapper.updateByPrimaryKey(wallet);
    }

    @Override
    public Wallet get(Long userId) {
        return walletMapper.selectByPrimaryKey(userId);
    }
}
